﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using Arizu.Repository;

namespace AiRiZu.User
{
    public class ReImageName : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Session["logId"] == null)
            {
                return;
            }

            AirizuUser user = AirizuUser.CreateInstance();

            string url = context.Request.Params["url"].ToString().Split(',')[0];
            url = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "user/" + url;

            FileInfo file = new FileInfo(url);
            string tmpName = System.IO.Path.GetTempFileName();
            string fileName = tmpName.Substring(0, 5) + context.Session["logId"] +  "." + file.Extension;

            user.UpdateImgName(int.Parse(context.Session["logId"].ToString()), fileName);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
